package com.dailyblue.project.smbms.alibaba.stock.service.impl;

import com.dailyblue.project.smbms.alibaba.stock.feign.AddressFeign;
import com.dailyblue.project.smbms.alibaba.stock.mapper.StockMapper;
import com.dailyblue.project.smbms.alibaba.stock.service.StockService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class StockServiceImpl implements StockService {
    @Resource
    private StockMapper mapper;
    @Resource
    private AddressFeign addressFeign;

    @Override
    public void stock(String aid, String order) {
        String uid = addressFeign.find(aid).getData().toString();
        String[] array = order.split(",");
        for (int i = 0; i < array.length; i++) {
            String s = array[i];
            String[] aa = s.split("=");
            String gid = aa[0];
            String num = aa[1];
            mapper.updateStock(gid, num);
            mapper.insertStockLog(uid, gid, num);
        }
    }
}
